home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / print / gs261sr1.zip / GDEV4081.C < prev    next >
C/C++ Source or Header  |  1993-05-12  |  3KB  |  96 lines

  1. /* Copyright (C) 1991 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* gdev4081.c */
  20. /* Ricoh 4081 laser printer driver for Ghostscript */
  21. #include "gdevprn.h"
  22.  
  23. #define X_DPI 300            /* pixels per inch */
  24. #define Y_DPI 300            /* pixels per inch */
  25.  
  26. /* The device descriptor */
  27. private dev_proc_print_page(r4081_print_page);
  28. gx_device_printer gs_r4081_device =
  29.   prn_device(prn_std_procs, "r4081",
  30.     85,                /* width_10ths, 8.5" */
  31.     110,                /* height_10ths, 11" */
  32.     X_DPI, Y_DPI,
  33.     0.25, 0.16, 0.25, 0.16,        /* margins */
  34.     1, r4081_print_page);
  35.  
  36. /* ------ Internal routines ------ */
  37.  
  38.  
  39. /* Send the page to the printer. */
  40. private int
  41. r4081_print_page(gx_device_printer *pdev, FILE *prn_stream)
  42. {    
  43.     int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
  44.     int out_size = ((pdev->width + 7) & -8) ;
  45.     byte *out = (byte *)gs_malloc(out_size, 1, "r4081_print_page(out)");
  46.     int lnum = 0;
  47.     int last = pdev->height;
  48.  
  49.     /* Check allocations */
  50.     if ( out == 0 )
  51.     {    if ( out )
  52.             gs_free((char *)out, out_size, 1,
  53.                 "r4081_print_page(out)");
  54.         return -1;
  55.     }
  56.  
  57.     /* find the first line which has something to print */
  58.     while ( lnum < last )
  59.     {
  60.         gdev_prn_copy_scan_lines(pdev, lnum, (byte *)out, line_size);
  61.         if ( out[0] != 0 ||
  62.              memcmp((char *)out, (char *)out+1, line_size-1)
  63.            )
  64.             break;
  65.         lnum ++;
  66.     }
  67.  
  68.     /* find the last line which has something to print */
  69.     while (last > lnum) {
  70.         gdev_prn_copy_scan_lines(pdev, last-1, (byte *)out, line_size);
  71.         if ( out[0] != 0 ||
  72.              memcmp((char *)out, (char *)out+1, line_size-1)
  73.            )
  74.             break;
  75.         last --;
  76.     }
  77.  
  78.     /* Initialize the printer and set the starting position. */
  79.     fprintf(prn_stream,"\033\rP\033\022YB2 \033\022G3,%d,%d,1,1,1,%d@",
  80.             out_size, last-lnum, (lnum+1)*720/Y_DPI);
  81.  
  82.     /* Print lines of graphics */
  83.     while ( lnum < last )
  84.        {
  85.         gdev_prn_copy_scan_lines(pdev, lnum, (byte *)out, line_size);
  86.         fwrite(out, sizeof(char), line_size, prn_stream);
  87.         lnum ++;
  88.        }
  89.  
  90.     /* Eject the page and reinitialize the printer */
  91.     fputs("\f\033\rP", prn_stream);
  92.  
  93.     gs_free((char *)out, out_size, 1, "r4081_print_page(out)");
  94.     return 0;
  95. }
  96.